package com.neu.json;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.neu.entity.TBUser;

public class JsonDemo01 {
  public static void method() {
	  JSONObject json = new JSONObject();
	  json.put("id", 1);
	  json.put("username", "师张杰");
	  json.put("userpass", "想知道我的密码，那么不可能的");
	  json.put("id", 2);
	  json.put("username", "张杰师");
	  json.put("userpass", "不想告诉你");
	  
	  	TBUser tu=JSON.toJavaObject(json, TBUser.class);
	  System.out.println(tu);
  }
  
  public static void method01() {
	  TBUser tb = new TBUser(1, "哎呀", "不知道");
	  TBUser tb1 = new TBUser(2, "我去", "不和你说");
	  List<TBUser> list = new ArrayList<>();
	  list.add(tb);
	  list.add(tb1);
	 Object h1 = JSON.toJSON(list);
	 String h2 = JSON.toJSONString(list);
	 System.out.println(h1);
	 System.out.println(h2);
  }
  public static void main(String[] args) {
	method();
	method01();
}
}
